home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / pressgen / an312x.exe / DOIT.C next >
C/C++ Source or Header  |  1993-10-15  |  3KB  |  111 lines

  1. /*
  2.  ████████████████████████████████████████████████████████████████████████████
  3.  █                                                                          █
  4.  █ doit.c                                                                   █
  5.  █                                                                          █
  6.  █ Submit a "job" to the job server.  A job is a DOS command line.          █
  7.  █                                                                          █
  8.  ████████████████████████████████████████████████████████████████████████████
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <ctype.h>
  14. #include <mem.h>
  15. #include <conio.h>
  16. #include <io.h>
  17. #include <string.h>
  18. #include "..\doit.h"
  19. #include <nwcalls.h>
  20.  
  21. #define NWDOS
  22.  
  23. NWCCODE            cCode;
  24. char            response;
  25. DWORD            queueID,
  26.             serverID;
  27. NWFILE_HANDLE        fileHandle;
  28. char            inBuf[255];
  29. size_t            buflen;
  30. NWCONN_HANDLE        connID;
  31. NWQueueJobStruct    jobStructure;
  32.  
  33. void main()
  34. {
  35.    cCode = NWCallsInit(NULL, NULL);
  36.    if (cCode == 0)
  37.         printf("Call to NWCallsInit successful\n");
  38.    else {
  39.         printf("Call to NWCallsInit failed\n");
  40.         exit(-1);
  41.    }
  42.  
  43.     /* Get the connection ID of the file server that has the job server's queue */
  44.    cCode = NWGetDefaultConnectionID(&connID);
  45.    if (cCode == 0)
  46.         printf("Call to NWGetDefaultConnectionID successful\n");
  47.    else {
  48.         printf("Call to NWGetDefaultConnectionID failed\n");
  49.         exit(-1);
  50.    }
  51.  
  52.     /* get the bindery object ID of the job server */
  53.    cCode = NWGetObjectID(connID, JOBSERV_NAME, OT_DOIT, &serverID);
  54.    if (cCode == 0)
  55.         printf("Call to NWGetObjectID successful\n");
  56.    else
  57.         printf("Call to NWGetObjectID failed, cCode = %X\n", cCode);
  58.  
  59.     /* get the bindery object ID of the queue */
  60.    cCode = NWGetObjectID(connID, JOBSERV_NAME, OT_DOIT_Q, &queueID);
  61.    if (cCode == 0)
  62.         printf("Call to NWGetObjectID successful\n");
  63.    else
  64.         printf("Call to NWGetObjectID failed, cCode = %X\n", cCode);
  65.  
  66.     /* fill in the job entry structure */
  67.  
  68.     /* set the target server to that of the job server.*/
  69.    jobStructure.targetServerID = serverID;
  70.  
  71.     /* set the target execution time to immediate */
  72.    memset(jobStructure.targetExecutionTime, 0xFF, 6);
  73.  
  74.     /* set the target jobType according to job priority */
  75.     printf("High priority job?\n");
  76.     do {
  77.         printf("Y/N >");
  78.         response = toupper(getche());
  79.         printf("\n");
  80.     } while ((response != 'Y') && (response != 'N'));
  81.     if (response == 'Y')
  82.        jobStructure.jobType = DOIT_JOB_PRIORITY_1;
  83.     else
  84.        jobStructure.jobType = DOIT_JOB_PRIORITY_2;
  85.  
  86.     /* set the job for auto start */
  87.    jobStructure.jobControlFlags = 0x08;
  88.  
  89.     /* ceate a queue file so you can get back a file handle to write to */
  90.    cCode = NWCreateQueueFile2(connID, queueID, &jobStructure, &fileHandle);
  91.    if (cCode == 0)
  92.         printf("Call to NWCreateQueueFile2 successful\n");
  93.    else
  94.         printf("Call to NWCreateQueueFile2 failed, cCode = %X\n", cCode);
  95.  
  96.     /* get a command to send to the job server for execution */
  97.     printf("Please input a DOS command:");
  98.     gets(inBuf);
  99.     buflen = strlen(inBuf);
  100.  
  101.     /* write the command to the job file */
  102.     write(fileHandle,inBuf,buflen) ;
  103.  
  104.     /* close the file */
  105.    cCode = NWCloseFileAndStartQueueJob2(connID, queueID, jobStructure.jobNumber, fileHandle);
  106.    if (cCode == 0)
  107.         printf("Call to NWCloseFileAndStartQueueJob2 successful\n");
  108.    else
  109.         printf("Call to NWCloseFileAndStartQueueJob2 failed, cCode = %X\n", cCode);
  110. }
  111.